package com.zx.dao.impl;

import com.zx.dao.ClassesDao;
import com.zx.entity.Classes;
import com.zx.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ClassesDaoImpl implements ClassesDao {
    @Override
    public List<Classes> select(int did) {
        List<Classes> classesList = new ArrayList<>();
        try {
            Connection connection = JDBCUtil.getConnection();
            String sql = "select * from t_classes where d_id ="+did;
            System.out.println(sql);
            PreparedStatement ps = connection.prepareStatement(sql);
            ResultSet resultSet = ps.executeQuery();
            while (resultSet.next()){
                int cid = resultSet.getInt("cid");
                String cname = resultSet.getString("cname");
                Classes classes = new Classes();
                classes.setCid(cid);
                classes.setCname(cname);
                classesList.add(classes);
            }
            return classesList;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return classesList;
    }
}
